cmake_minimum_required(VERSION 3.5)

project(Demo LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
# Check http://doc.qt.io/qt-5/deployment-android.html for more information.
# They need to be set before the find_package(Qt5 ...) call.

#if(ANDROID)
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
#    if (ANDROID_ABI STREQUAL "armeabi-v7a")
#        set(ANDROID_EXTRA_LIBS
#            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
#            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
#    endif()
#endif()

find_package(Qt5 COMPONENTS Widgets LinguistTools REQUIRED)



set(TS_FILES Demo_zh_CN.ts)

# 设置跨平台配置
if(WIN32)
  message(STATUS "This is a Windows platform.")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWIN32")
  add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/source-charset:utf-8>")
  #set(CMAKE_WIN32_EXECUTABLE ON)
  #修改路径  
  set(glslang_DIR C:/vcpkg/packages/glslang_x64-windows/share/glslang/)
else()
  #修改路径
  set(glslang_DIR /home/vcpkg/vcpkg/packages/glslang_arm64-linux/share/glslang/)
endif()

set(vsg_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vsg/cmake)

if (glslang_DIR)
   set(FIND_DEPENDENCY_glslang "find_package(glslang ${GLSLANG_MIN_VERSION} CONFIG REQUIRED)")
else()
    message(FATAL_ERROR " no glslang ")
endif()

add_subdirectory(vsg)
add_subdirectory(vsgXchange)
add_subdirectory(vsgQt)

set(Qt5_RESOURCES vsgUI.qrc)
file(GLOB Qt5_RESOURCES_SRC "${Qt5_RESOURCES}")

# 获取当前源码目录
set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})

# 查找所有 .cpp 和 .h 文件
file(GLOB SOURCES "${SOURCE_DIR}/*.cpp")
file(GLOB HEADERS "${SOURCE_DIR}/*.h")
# 添加可执行文件，包含所有找到的源文件

if(ANDROID)
  add_library(Demo SHARED
     vsgUI2.ui
     ${SOURCES} 
     ${HEADERS}
     ${Qt5_RESOURCES_SRC}
     ${TS_FILES}
  )
else()
  add_executable(Demo
     vsgUI2.ui
     ${SOURCES} 
     ${HEADERS}
     ${Qt5_RESOURCES_SRC}
     ${TS_FILES}
  )
endif()

set(CMAKE_INSTALL_PREFIX "../vsgqt/bin")

target_link_libraries(Demo PRIVATE Qt5::Widgets vsgQt)
#target_link_options(${PROJECT_NAME} PRIVATE "-subsystem:windows")
# 设置目标目录
set(DESTINATION_DIR "../vsgqt/bin")



# 编译完成后将可执行文件拷贝到目标目录
add_custom_command(
    TARGET Demo
    POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:Demo> ${DESTINATION_DIR}
)

qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
